/**
 * jims
 */
package com.jims.master.modules.nurse.web;


import com.jims.master.modules.sys.utils.UserUtils;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import com.jims.master.common.data.StringData;
import com.jims.master.common.web.BaseController;
import com.jims.master.common.utils.StringUtils;
import com.jims.master.modules.nurse.entity.NurseVitalSignsRec;
import com.jims.master.modules.nurse.service.NurseVitalSignsRecService;

import java.util.Date;
import java.util.List;

/**
 * 病人体征记录Controller
 * @author CTQ
 * @version 2017-06-01
 */
@Controller
@RequestMapping(value = "${adminPath}/nurse/nurseVitalSignsRec")
public class NurseVitalSignsRecController extends BaseController {

	@Autowired
	private NurseVitalSignsRecService nurseVitalSignsRecService;
	
	@ModelAttribute
	public NurseVitalSignsRec get(@RequestParam(required=false) String id) {
		NurseVitalSignsRec entity = null;
		if (StringUtils.isNotBlank(id)){
			entity = nurseVitalSignsRecService.get(id);
		}
		if (entity == null){
			entity = new NurseVitalSignsRec();
		}
		return entity;
	}
	
	@RequiresPermissions("user")
	@RequestMapping(value = {"index", ""})
	public String list(NurseVitalSignsRec nurseVitalSignsRec,  Model model) {
		List<NurseVitalSignsRec> list = nurseVitalSignsRecService.findList(nurseVitalSignsRec);
		model.addAttribute("list", list);
		return "modules/nurse/nurseVitalSignsRecIndex";
	}

	@RequiresPermissions("user")
	@RequestMapping(value = "form")
	public String form(NurseVitalSignsRec nurseVitalSignsRec, Model model) {
		nurseVitalSignsRec.setTimePoint(new Date());
        if(StringUtils.isBlank(nurseVitalSignsRec.getTempItem().getNurseGroups())) {
            nurseVitalSignsRec.getTempItem().setNurseGroups("2");
        }
		model.addAttribute("nurseVitalSignsRec", nurseVitalSignsRec);
		return "modules/nurse/nurseVitalSignsRecForm";
	}

	@RequiresPermissions("user")
	@RequestMapping(value = "save")
	@ResponseBody
	public StringData save(NurseVitalSignsRec nurseVitalSignsRec) {
	    StringData data=new StringData();
		nurseVitalSignsRec.setRecordingDate(new Date());
		nurseVitalSignsRec.setNurse(UserUtils.getUser().getId());
		nurseVitalSignsRec.setWardCode(UserUtils.getUser().getOrgDept()!=null?UserUtils.getUser().getOrgDept().getId():"");
		int i=nurseVitalSignsRecService.save(nurseVitalSignsRec);
        if(i>0){
            data.setCode("success");
            data.setData("保存病人项目事件成功");
        }else{
            data.setCode("error");
            data.setData("保存病人项目事件失败");
        }
        return data;
	}
	@RequiresPermissions("user")
	@RequestMapping(value = "delete")
	@ResponseBody
	public StringData delete(NurseVitalSignsRec nurseVitalSignsRec) {
	    StringData data=new StringData();
		int i=nurseVitalSignsRecService.delete(nurseVitalSignsRec);
        if(i>0){
            data.setCode("success");
            data.setData("删除病人项目事件成功");
        }else{
            data.setCode("error");
            data.setData("删除病人项目事件失败");
        }
		return data;
	}

	}